import QtQuick 1.1
import com.nokia.symbian 1.1
//import "core/lines.js" as Logic

MainPage {
    Column{
        id: grid
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
        spacing: 10


        Text{
            width: 100
            height:50
            color: "white"
            text: "New game"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    gamePage.restartGame = true;
                    pageStack.replace(gamePage);
                }
            }
        }

        Text{
            id: contBtn
            visible: false
            width: 100
            height:50
            color: "white"
            text: "Continue"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    gamePage.continueGame = true;
                    pageStack.replace(gamePage);
                }
            }
        }

        Text{ width: 100
            height:50
            color: "white"
            text: "High scores"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    scorePage.populateModel();
                    pageStack.replace(scorePage);
                }
            }
        }

        Text{
            width: 100
            height:50
            color: "white"
            text: "Options"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            MouseArea{
                anchors.fill: parent
                onClicked: {
                    pageStack.replace(optionPage);
                }
            }
        }


        Text{
            width: 100
            height:50
            color: "white"
            //anchors.verticalCenter: parent
            //anchors.horizontalCenter: parent
            text: "Help"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            //anchors.horizontalCenter: parent.horizontalCenter
            MouseArea{
                anchors.fill: parent
                onClicked: pageStack.replace(helpPage)
            }
        }

        Text{
            width: 100
            height:50
            color: "white"
            //anchors.verticalCenter: parent
            //anchors.horizontalCenter: parent
            text: "About"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            //anchors.horizontalCenter: parent.horizontalCenter
            MouseArea{
                anchors.fill: parent
                onClicked: pageStack.replace(aboutPage)
            }
        }
    }
    onStatusChanged:  if(status == 2){
                          var db = openDatabaseSync("Lines98DB", "1.0", "Local Lines 98 SQL!", 1000000);
                          var available = true;
                          db.transaction(
                                      function(tx) {
                                          var rs = tx.executeSql('SELECT name FROM sqlite_master WHERE name="SavedGame"');
                                          console.debug(rs.rows.length + " from menu page");
                                          if (rs.rows.length == 0) {
                                              available = false;
                                          }
                                      }
                                      )
                          if(available){
                              contBtn.visible = true;
                          }else{
                              contBtn.visible = false;
                          }
                      }
}


